Java - invoke、newInstance反射调用的各种方式收集

一、invoke

Method.invoke

1
2
Method method = Threedr3am.class.getMethod("a");
method.invoke(null);

MethodAccessor.invoke

1
2
3
4
Method method = Threedr3am.class.getMethod("a");
ReflectionFactory reflectionFactory = AccessController.doPrivileged(new sun.reflect.ReflectionFactory.GetReflectionFactoryAction());
MethodAccessor methodAccessor = reflectionFactory.newMethodAccessor(method);
methodAccessor.invoke(null, null);

JSClassLoader.invoke

1
2
Method method = Main.class.getDeclaredMethod("a");
JSClassLoader.invoke(method, null, null);

二、newInstance

JSClassLoader.newInstance

1
2
Constructor constructor = Main.class.getConstructor();
JSClassLoader.newInstance(constructor, null);